package com.td.module.equipment.convert.info;

import com.td.framework.common.pojo.PageResult;
import com.td.module.equipment.controller.admin.info.vo.InfoCreateReqVO;
import com.td.module.equipment.controller.admin.info.vo.InfoExcelVO;
import com.td.module.equipment.controller.admin.info.vo.InfoRespVO;
import com.td.module.equipment.controller.admin.info.vo.InfoUpdateReqVO;
import com.td.module.equipment.dal.dataobject.info.InfoDO;
import com.td.module.equipment.framework.core.dto.EquipmentInfoCreateDto;
import com.td.module.equipment.framework.core.dto.EquipmentInfoUpdateDto;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 设备信息 Convert
 *
 * @author 王翔翔
 */
@Mapper
public interface InfoConvert {

    InfoConvert INSTANCE = Mappers.getMapper(InfoConvert.class);

    InfoDO convert(InfoCreateReqVO bean);

    InfoDO convert(InfoUpdateReqVO bean);

    InfoRespVO convert(InfoDO bean);

    List<InfoRespVO> convertList(List<InfoDO> list);

    PageResult<InfoRespVO> convertPage(PageResult<InfoDO> page);

    List<InfoExcelVO> convertList02(List<InfoDO> list);

    default InfoDO convert(EquipmentInfoCreateDto bean) {

        if ( bean == null ) {
            return null;
        }

        InfoDO.InfoDOBuilder infoDO = InfoDO.builder();

        infoDO.stationId(bean.getExt().getStationID());
        infoDO.monitorTime(bean.getExt().getMonitorTime());
        if (bean.getExt().getTerminalStatus() != null) {
            infoDO.volt(bean.getExt().getTerminalStatus().getVolt());
            infoDO.rssi(bean.getExt().getTerminalStatus().getRssi());
            infoDO.imei(bean.getExt().getTerminalStatus().getImei());
            infoDO.longitude(bean.getExt().getTerminalStatus().getLongitude());
            infoDO.latitude(bean.getExt().getTerminalStatus().getLatitude());
            infoDO.dotled(bean.getExt().getTerminalStatus().getDotled());
            infoDO.controlOp(bean.getExt().getTerminalStatus().getControlOp());
            infoDO.version(bean.getExt().getTerminalStatus().getVersion());
        }
        infoDO.isOnline(bean.getIsOnline());

        return infoDO.build();

    }

    default InfoDO convert(EquipmentInfoUpdateDto bean) {

        if ( bean == null ) {
            return null;
        }

        InfoDO.InfoDOBuilder infoDO = InfoDO.builder();

        infoDO.id( bean.getId() );
        infoDO.stationId(bean.getExt().getStationID());
        infoDO.monitorTime(bean.getExt().getMonitorTime());
        if (bean.getExt().getTerminalStatus() != null) {
            infoDO.volt(bean.getExt().getTerminalStatus().getVolt());
            infoDO.rssi(bean.getExt().getTerminalStatus().getRssi());
            infoDO.imei(bean.getExt().getTerminalStatus().getImei());
            infoDO.longitude(bean.getExt().getTerminalStatus().getLongitude());
            infoDO.latitude(bean.getExt().getTerminalStatus().getLatitude());
            infoDO.dotled(bean.getExt().getTerminalStatus().getDotled());
            infoDO.controlOp(bean.getExt().getTerminalStatus().getControlOp());
            infoDO.version(bean.getExt().getTerminalStatus().getVersion());
        }
        infoDO.isOnline(bean.getIsOnline());

        return infoDO.build();

    }

}
